<template>
  <div class="custom-body" :style="borderStyle">
    <div class="custom-right">
      <div class="custom-divider" :style="{backgroundColor: themes.bkys}">
        <div class="divider-title" :style="titleFontSize">
          <span>{{ column.title }}</span>
        </div>
        <div class="divider-content" :style="contentFontSize">{{ column.content }}</div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'AppDividerV1',
  props: {
    temp: {
      type: Object,
      default() {
        return {};
      }
    },
    showHeader: {
      type: Boolean,
      default: true
    },
    layout: {
      type: Object,
      default: () => {
        return {};
      }
    }
  },
  data() {
    return {
      column: null,
      titleFontSize: { fontSize: '16px' },
      contentFontSize: { fontSize: '13px' },
      columnStyle: {},
      borderStyle: {}
    };
  },
  computed: {
    themes() {
      return this.$store.getters.theme;
    },
    liStyle() {
      const width = (100 / this.column.row).toFixed(2);
      const height = (100 / Math.ceil(this.column.size / this.column.row)).toFixed(2);
      return { width: width + '%', height: height + '%' };
    }
  },
  watch: {
    layout: {
      handler(newName, old) {
        this.columnStyle = newName;
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    },
    temp: {
      handler(newData, oldData) {
        if (this.showHeader) {
          const pzx = JSON.parse(newData.data.pzx);
          this.column = pzx;
        } else {
          const pzx = JSON.parse(newData.pzx);
          this.column = pzx;
        }
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    },
    themes: {
      handler(val, oldVal) {
        this.borderStyle.borderRadius = val.bkdx;
        if (this.temp.sfxsbk === true) {
          this.borderStyle.border = '1px solid ' + val.bkys;
        }
        if (this.temp.bkyy === true) {
          this.borderStyle.boxShadow = '0 2px 4px rgba(0, 0, 0, .12)';
        }
        this.borderStyle.background = val.columnGroundColor;
        this.borderStyle.color = val.fontColor;
        this.titleFontSize = { fontSize: this.column.titleFontSize + 'px', background: val.columnGroundColor };
        this.contentFontSize = { fontSize: this.column.contentFontSize + 'px' };
        this.contentFontSize = Object.assign({}, this.contentFontSize);
        this.titleFontSize = Object.assign({}, this.titleFontSize);
        this.borderStyle = Object.assign({}, this.borderStyle);
      },
      immediate: true, // 父组件第一次传值时，执行handler，false则第一次不执行
      deep: false // formType为对象时，设置为true，此属性监听对象发生变化
    }
  }
};
</script>

<style scoped>
.custom-body {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  flex-flow: row nowrap;
  border-radius: 4px;
  box-sizing: border-box;
  overflow: hidden;
}
.custom-right {
  flex: 1 1 auto;
  height: 100%;
  position: relative;
  padding: 0px 20%;
  box-sizing: border-box;
}
.custom-divider {
  position: relative;
  height: 2px;
  width: 100%;
  margin: 24px 0;
  display: block;
}
.divider-title{
  position: absolute;
  left: 50%;
  transform: translateX(-50%) translateY(-50%);
  right: 0px;
  top:0px;
  height: 50px;
  text-align: center;
}
.divider-title span{
  height: 50px;
  line-height: 50px;
  padding: 0px 20px;
  box-sizing: border-box;
}
.divider-content {
  position: absolute;
  text-align: center;
  line-height: 20px;
  left: 0px;
  right: 0px;
  top: 25px;
}
</style>
